<template>
  <el-dialog
    :title="'审核'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="110px">
      <el-form-item label="审核结果" prop="status">
        <el-select v-model="dataForm.status" clearable >
          <el-option value="3" label="审核通过" key="3"></el-option>
          <el-option value="2" label="审核不通过" key="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="备注" prop="status">
        <el-input
          type="textarea"
          :rows="2"
          placeholder="请输入备注"
          v-model="dataForm.auditingRemarks">
        </el-input>
      </el-form-item>

    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        defaultCascaderValue: [], // 默认值
        myProp: {
          value: 'value',
          label: 'label',
          checkStrictly: true
        },
        options: [],
        optionsCustomer: [],
        storageOptions: [],
        visible: false,
        dataForm: {
          id: 0,
          auditingRemarks: '',
          status: ''
        },
        dataRule: {
          status: [
            { required: true, message: '审核结果不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/app/entoutbound/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.auditingRemarks = data.entOutbound.auditingRemarks
                if (data.entOutbound.status !== 1) {
                  this.dataForm.status = data.entOutbound.status
                }
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/app/entoutbound/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'auditingRemarks': this.dataForm.auditingRemarks,
                'status': this.dataForm.status
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
